{extend name="admin@public/basic" /}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/css/admin/public.css" media="all"/>
{/block}

{block name="cotent"}

{if empty($module_list)}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>暂无节点信息，可以先刷新节点信息 =》
        <button class="layui-btn layui-btn-normal refresh_node">刷新节点</button>
    </legend>
</fieldset>
{/if}

<div class="layui-tab layui-tab-brief" lay-filter="module">
    <ul class="layui-tab-title">
        {foreach module_list as $vo}
        <li {if $vo.is_selectd==true}class="layui-this"{/if} lay-id="{$vo.id}">{$vo.title|default=''}【{$vo.node|default=''}】</li>
        {/foreach}
    </ul>
    <div class="layui-tab-content">
        {foreach module_list as $vo}
        <div class="layui-tab-item {if $vo.is_selectd==true}layui-show{/if}">
            <table id="{$vo.node}Table" lay-filter="{$vo.node}Table"></table>
            <script type="text/html" id="checkStatus">
                <input type="checkbox" name="{{d.id}}" value="{{d.is_auth}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="modifyStatus" {{ d.is_auth== 1 ? 'checked' : '' }}>
            </script>
        </div>
        {/foreach}
    </div>
</div>
{/block}

{block name="script"}
<script>
    layui.use(['laydate', 'form', 'layer', 'table', 'laytpl', 'element'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table,
            laydate = layui.laydate,
            element = layui.element;

        /**{foreach module_list as $vo}**/
        $.form.table("{$vo.node}", '{:url("$thisRequest")}?module={$vo.node}', [[
            {field: 'node', title: '系统节点', minWidth: 200, align: 'left', sort: true},
            {field: 'title', title: '节点名称', edit: 'text', minWidth: 200, align: "center", style: 'background-color: #009688; color: #fff;', sort: true},
            {field: 'create_at', title: '创建时间', align: 'center', sort: true},
            {field: 'is_auth', title: '节点控制', width: 150, templet: '#checkStatus', unresize: true, align: "center"},
        ]], false);
        /**{/foreach}**/

            //Hash地址的定位
        var layid = location.hash.replace(/^#module=/, '');
        element.tabChange('module', layid);
        element.on('tab(module)', function (elem) {
            location.hash = 'module=' + $(this).attr('lay-id');
        });

        /**
         * 修改状态
         */
        $.form.switch('modifyStatus', '{:url("$thisClass/status")}');

        /**
         * 监听字段值编辑
         */
        /**{foreach module_list as $vo}**/
        $.form.editField("{$vo.node}Table", '{:url("$thisRequest")}');
        /**{/foreach}**/


        /**
         * 工具栏操作
         */
        /**{foreach module_list as $vo}**/
        table.on("tool({$vo.node}Table)", function (obj) {
            var layEvent = obj.event,
                data = obj.data;

            //删除
            if (layEvent === 'delBtn') {
                $.msg.confirm('确定删除？', function () {
                    $.request.post('{:url("$thisClass/del")}', {id: data.id}, function (res) {
                        $.msg.success(res.msg, function () {
                            $.tool.reload();
                        });
                    });
                });
                return false;
            }
        });
        /**{/foreach}**/

    });
</script>
{/block}